
import { createStore } from 'vuex'

// 引入插件
import createPersistedState from "vuex-persistedstate"

export default createStore({
  state: {
    // 个人账户信息
    userInfo: {
      access_token: "",
      expires_in: "",
      token_type: ""
    },
  },
  mutations: {
    setUserInfo(state, data) {
      state.userInfo = data;
    },
  },
  actions: {
    setUserInfo(context, data) {
      context.commit("setUserInfo", data)
    },
  },
  // vuex数据持久化配置 
  plugins: [
    createPersistedState({
      // 存储方式：localStorage、sessionStorage、cookies
      storage: window.localStorage,
      // 存储的 key 的key值
      key: "store",
    })
  ]
})
